/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.safetytask.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.domain.DataBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.common.web.Util;
import com.koron.safetytask.domain.CustomFormData;
import com.koron.safetytask.domain.UserTask;
import com.koron.safetytask.domain.UserTaskFollow;
import com.koron.safetytask.domain.UserTaskResult;
import com.koron.safetytask.service.api.CustomFormDataService;
import com.koron.safetytask.service.api.UserTaskService;
import com.koron.safetytask.utils.BusinessCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

@Api(tags = "userTask", description = "用户任务接口类")
@RestController
@RequestMapping("/userTask")
public class UserTaskController {

    private static final Logger log = LoggerFactory.getLogger(UserTaskController.class);
    @Autowired
    private UserTaskService taskService;

    @Autowired
    private CustomFormDataService customFormDataService;

    @Autowired
    private Util util;

    @ApiOperation("保存用户任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "operatorType", value = "操作类型，0保存草稿，1提交任务，提交后不允许修改" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "任务id,新增不传,修改必传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskName", value = "任务标题", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskDesc", value = "任务描述", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deadline", value = "结束时间", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiverCode", value = "任务执行人code和所在部门code,格式为userCode_deptCode,多个之间yong,分开", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiverName", value = "任务执行人名称和所在部门名称,格式为userName_deptName,多个之间yong,分开", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiverNum", value = "任务执行人数" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "taskType", value = "任务类型" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "任务状态,0 待办,1 已办" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "copyPerson", value = "任务抄送人code，多个之间用，分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "copyPersonName", value = "任务抄送人名称和所在部门名称，多个之间用，分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keepAttAddress", value = "要保留的任务附件，多个之间用，分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keepAttAddress", value = "要删除的任务附件，多个之间用，分开" , dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/save.htm", method = RequestMethod.POST)
    public MessageBean<Integer> save(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore UserTask task, @RequestParam(required = false) final String userCode,
                                     @RequestParam(required = true) final Integer operatorType,@RequestParam(required = false) final String keepAttAddress, @RequestParam(required = false) final String delAttAddress, MultipartFile[] files) {
        MessageBean<Integer> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        task.setUpdateTime(new Date());
        task.setUpdateUser(user.getName());
        task.setInitiatorCode(user.getCode());
        task.setInitiatorName(user.getName());
        msg = taskService.save(user, task,operatorType, files, keepAttAddress, delAttAddress);
        return msg;
    }


    @ApiOperation("根据主键删除用户任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "任务id,", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/delete.htm", method = RequestMethod.POST)
    public MessageBean<Integer> delete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = true) final String id) {
        if (null == user) {
            MessageBean<Integer> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NOT_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<Integer> msg = taskService.delete(id);
        return msg;
    }


    @ApiOperation("根据主键获取用户任务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "任务id,", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/details.htm", method = RequestMethod.POST)
    public MessageBean<UserTask> details(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = true) final String id) {
        if (null == user) {
            MessageBean<UserTask> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NOT_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<UserTask> msg = taskService.query(id);
        return msg;
    }


    @ApiOperation("获取指派用户任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskName", value = "任务标题" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deadline", value = "结束时间" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键词" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/queryForInitiator.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<UserTask>> queryForInitiator(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) String userCode,
                                                             @RequestParam(required = false) final String taskName, @RequestParam(required = false) final @JsonFormat(pattern = "yyyy-MM-dd")
                                                             @DateTimeFormat(pattern = "yyyy-MM-dd") Date deadline,@RequestParam(required = false) String keyword, @RequestParam(required = true) Integer page, @RequestParam(required = true) Integer pageSize) {
        MessageBean<DataBean<UserTask>> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        Integer start = null;
        if (null != page) {
            if (pageSize != null) {
                if (pageSize <= 0)
                    pageSize = 10;
            }
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        msg = taskService.queryForInitiator(user.getCode(), taskName, deadline, start, pageSize,keyword);
        msg.getData().setPageNo((page == null || page == 0) ? 1 : page);
        msg.getData().setPageSize((pageSize == null || pageSize == 0) ? 10 : pageSize);
        return msg;
    }


    @ApiOperation("获取用户任务接收的列表,待办或者已办通过state字段区分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskName", value = "任务标题" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "任务状态,0 待办,1 已办", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deadline", value = "结束时间" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键词" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/queryForReceiver.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<UserTask>> queryForReceiver(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) String userCode,
                                                            @RequestParam(required = false) final String taskName, @RequestParam(required = false) final Integer state, @RequestParam(required = false) final @JsonFormat(pattern = "yyyy-MM-dd")
                                                            @DateTimeFormat(pattern = "yyyy-MM-dd") Date deadline,@RequestParam(required = false) String keyword, @RequestParam(required = true) Integer page, @RequestParam(required = true) Integer pageSize) {
        MessageBean<DataBean<UserTask>> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        Integer start = null;
        if (null != page) {
            if (pageSize != null) {
                if (pageSize <= 0)
                    pageSize = 10;
            }
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        String code = user.getCode();
        msg = taskService.queryForReceiver(code, state, taskName, deadline, start, pageSize,keyword);
        msg.getData().setPageNo((page == null || page == 0) ? 1 : page);
        msg.getData().setPageSize((pageSize == null || pageSize == 0) ? 10 : pageSize);
        return msg;
    }


    @ApiOperation("获取所有用户任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskName", value = "任务标题" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiverCode", value = "任务接收人code和所在部门code,格式为userCode_deptCode" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deadline", value = "结束时间" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/queryAllByCondition.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<UserTask>> queryAllByCondition(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) final String taskName, @RequestParam(required = false) final @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd") Date deadline, @RequestParam(required = false) final String receiverCode, @RequestParam(required = true) Integer page, @RequestParam(required = true) Integer pageSize) {
        if (null == user) {
            MessageBean<DataBean<UserTask>> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NOT_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return messageBean;
        }
        Integer start = null;
        if (null != page) {
            if (pageSize != null) {
                if (pageSize <= 0)
                    pageSize = 10;
            }
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        String userCode = "";//根据当前登录人的code
        MessageBean<DataBean<UserTask>> msg = taskService.queryAllByCondition(taskName, deadline, receiverCode, start, pageSize);
        msg.getData().setPageNo((page == null || page == 0) ? 1 : page);
        msg.getData().setPageSize((pageSize == null || pageSize == 0) ? 10 : pageSize);
        log.info(msg.getData().getList().toString());
        return msg;
    }


    @ApiOperation("填写任务执行结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "新增时不填，修改时必填" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userTaskId", value = "用户任务id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "resultDesc", value = "任务结果描述" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keepAttAddress", value = "要保留的任务结果附件，多个之间用，分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "delAttAddress", value = "要删除的任务结果附件，多个之间用，分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isDraft", value = "保存状态，0草稿，1提交", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "tbaleCode", value = "表格code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "customFormList", value = "自定义表单数据" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "approver", value = "审批人" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "title", value = "标题" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "description", value = "描述" , paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/saveUserTaskResult.htm", method = RequestMethod.POST)
    public MessageBean<Integer> saveUserTaskResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore UserTaskResult result, @RequestParam(required = false) final String userCode,
                                                   @RequestParam(required = false) final String keepAttAddress, @RequestParam(required = false) final String delAttAddress,
                                                   @RequestParam(required = false) final String tbaleCode, @RequestParam(required = false) final String customFormList,
                                                   @RequestParam(required = false) final String approver,@RequestParam(required = false) final String title,@RequestParam(required = false) final String description,
                                                   MultipartFile[] files) {
        MessageBean<Integer> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }

        // 处理自定义表单数数据
        List<CustomFormData> beanList = new ArrayList<>();
        if (StringUtils.isNotEmpty(customFormList)) {
            Integer maxRowId = null; //存储数据表中已有数据的最高rowId
            // 根据表格code，业务id查询表格中数据的最高rowId
            MessageBean<Integer> messageBean = customFormDataService.queryMaxRow(tbaleCode, result.getUserTaskId());
            if (messageBean.getCode() == BusinessCode.SUCCESS.getCode()) {
                maxRowId = messageBean.getData();
            } else {
                return messageBean;
            }
            //将字符串转成json
            JSONArray array = JSON.parseArray(customFormList);
            for (int i = 0; i < array.size(); i++) {
                JSONArray jsonArray = array.getJSONArray(i);
                Iterator<Object> it = jsonArray.iterator();
                int count = 0;
                while (it.hasNext()) {
                    JSONObject json = (JSONObject) it.next();
                    String id = json.getString("id");
                    String rowId = json.getString("rowId");
                    String keyId = json.getString("keyId");
                    String addUser = json.getString("addUser");
                    String addUserName = json.getString("addUserName");
                    String addTime = json.getString("addTime");
                    String keyValue = json.getString("key" + count);
                    CustomFormData customFormData = new CustomFormData();
                    if (StringUtils.isNotEmpty(id)) {
                        customFormData.setId(id);
                    }
                    if (StringUtils.isNotEmpty(rowId)) {
                        customFormData.setRowId(Integer.valueOf(rowId));
                    } else {
                        customFormData.setRowId(maxRowId + i + 1);
                    }
                    if (StringUtils.isNotEmpty(addTime)) {
                        customFormData.setAddTime(new Date(Long.parseLong(addTime)));
                    }
                    if (StringUtils.isNotEmpty(addUser)) {
                        customFormData.setAddUser(addUser);
                    }
                    if (StringUtils.isNotEmpty(addUserName)) {
                        customFormData.setAddUserName(addUserName);
                    }
                    customFormData.setTbaleCode(tbaleCode);
                    customFormData.setBusinessId(result.getUserTaskId());
                    customFormData.setKeyId(keyId);
                    customFormData.setKeyValue(keyValue);
                    beanList.add(customFormData);
                    count++;
                }
            }
        }


        result.setUpdateTime(new Date());
        result.setUpdateUser(user.getName());
        result.setExecutorCode(user.getCode());//设置当前登录人的code,暂时给默认值
        return taskService.saveUserTaskResult(user, result, files, keepAttAddress, delAttAddress, beanList, tbaleCode,approver,title,description);
    }


    @ApiOperation("(指派任务调用)根据任务id查询任务执行结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,pc端不传，app必传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskId", value = "用户任务id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/queryUserTaskResultByTaskId.htm", method = RequestMethod.POST)
    public MessageBean<List<UserTaskResult>> queryUserTaskResultByTaskId(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,@RequestParam(required = true) final String taskId) {
        MessageBean<List<UserTaskResult>> msg = new MessageBean<>();
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        return taskService.queryUserTaskResultByTaskId(user, taskId);
    }

    @ApiOperation("(待办/已办任务调用)根据任务id查询自己填写的任务执行结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "用户任务id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/queryMyUserTaskResult.htm", method = RequestMethod.POST)
    public MessageBean<UserTaskResult> queryMyUserTaskResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,  @RequestParam(required = true) final String taskId) {
        MessageBean<UserTaskResult> msg = new MessageBean<>();
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        return taskService.queryResultByUserTaskIdAndExecutorCode(user, taskId);
    }


    @ApiOperation("确认任务执行结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "任务结果id,必填", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isPass", value = "是否通过，0不通过，1通过", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "opinion", value = "任务结果描述" , dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/confirmUserTaskResult.htm", method = RequestMethod.POST)
    public MessageBean<Integer> confirmUserTaskResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore UserTaskResult result) {
        MessageBean<Integer> msg = new MessageBean<>();
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        result.setApproverCode(user.getCode());
        result.setApprovedTime(new Date());
        return taskService.confirmUserTaskResult(result);
    }


    @ApiOperation("关注任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "taskId", value = "任务结果id,必填", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/insertTaskFollow.htm", method = RequestMethod.POST)
    public MessageBean<Integer> insertTaskFollow(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore UserTaskFollow taskFollow, @RequestParam(required = false) final String userCode) {
        MessageBean<Integer> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        taskFollow.setFollowerCode(user.getCode());//先给一个默认值，到时候再给登录用户的code
        return taskService.insetUserTaskFollow(taskFollow);
    }


    @ApiOperation("取消关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "任务结果id,多个之间用，分开", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/deleteFollowBatch.htm", method = RequestMethod.POST)
    public MessageBean<Integer> deleteFollowBatch(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = true) final String ids) {
        if (null == user) {
            MessageBean<Integer> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NOT_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<Integer> msg = new MessageBean<>();
        if (StringUtils.isEmpty(ids)) {
            msg.setCode(BusinessCode.TASKFOLLOW_NOT_CHANGE_DATA.getCode());
            msg.setDescription(BusinessCode.TASKFOLLOW_NOT_CHANGE_DATA.getDescription());
            return msg;
        }
        String[] idArray = ids.split("[,，]");
        msg = taskService.batchDeleteTaskFollow(Arrays.asList(idArray));
        return msg;
    }


    @ApiOperation("获取用户关注的任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键词" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/queryByFollewCode.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<UserTask>> queryByFollewCode(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) final String userCode,@RequestParam(required = false) String keyword, @RequestParam Integer page, @RequestParam Integer pageSize) {
        MessageBean<DataBean<UserTask>> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        Integer start = null;
        if (null != page) {
            if (pageSize != null) {
                if (pageSize <= 0)
                    pageSize = 10;
            }
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        msg = taskService.queryByFollewCode(user.getCode(), start, pageSize,keyword);
        msg.getData().setPageNo((page == null || page == 0) ? 1 : page);
        msg.getData().setPageSize((pageSize == null || pageSize == 0) ? 10 : pageSize);
        return msg;
    }

    @ApiOperation("首页获取用户待办任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前登录用户code,app调用该接口必传，pc端不传" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/indexUnDeal.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<UserTask>> indexUnDeal(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String userCode, Integer page, Integer pageSize) {
        MessageBean<DataBean<UserTask>> msg = new MessageBean<>();
        List<StaffBean> staffBeanList = (List<StaffBean>) util.staff(userCode, null).getData();
        if (null == user) {
            if (null != staffBeanList && staffBeanList.size() > 0)
                user = staffBeanList.get(0);
        }
        if (null == user) {
            msg.setCode(BusinessCode.NOT_LOGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LOGIN.getDescription());
            return msg;
        }
        return taskService.indexUnDeal(user.getCode(), page, pageSize);
    }
}
